
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bridge;

import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author victor
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        final Bridge bridge = new Bridge();

//        final SynchronousQueue<Habitant> fromCityA = new SynchronousQueue<>();
//        final SynchronousQueue<Habitant> fromCityB = new SynchronousQueue<>();


        Thread habGenerator = new Thread(new Runnable() {

            private int i;

            @Override
            public void run() {
                while (true) {
                    Random random = new Random();

                    try {
                        Thread.currentThread().sleep(random.nextInt(2) * 1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    Habitant habitant;

                    if (random.nextBoolean()) {
                        habitant = new Habitant(bridge, ++i, 'B');
//                        fromCityA.add(habitant);
                        System.out.println("A new Habitant from A City to B City named: " + habitant);
                    } else {
                        habitant = new Habitant(bridge, ++i, 'A');
//                        fromCityB.add(habitant);
                        System.out.println("A new Habitant from B City to A City named: " + habitant);
                    }

                    habitant.start();
                }
            }
        });

        habGenerator.start();
    }
}
